const positionTpl = require('../views/position.html')
const template=require('art-template')

const positionController = {
   async render({res,router}){
     //获取数据
    let  listData=await this.getList().then(res=>res)
    //console.log(listData)
     //art-template 
     let tpl=template.render(positionTpl,{
       data: JSON.parse(listData)
     }) 
     
     console.log(tpl)
    res.render(positionTpl)
   
    //点击按钮 -- 》 路由的跳转   router.go('/position/add')

    $('#app-position-add').on('click',()=>{
      router.go('/position_add') //编程式导航
    })

  },
  getList(){
   return  $.ajax({
      url:"/api/position/find",
      success(res){
        return res
      }
    })
  }
}


module.exports = positionController